package com.AnywheeBt;

import java.util.List;
import com.AnywheeBt.bean.BtContact;
import android.util.Log;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothAvrcpController;
import android.bluetooth.BluetoothAvrcp;
import android.os.Handler;

public class SzhBAction {
	private static final String TAG = "AnywheeBtAction";	
    private static AnywheeBtActionListener mListener = null;
    public final static String BT_VOL_VAL ="15";
    public final static String BT_NAME_DEF ="ANW";
    public final static String AT_CMD_CA ="CA";	
    public final static String AT_CMD_CB ="CB";	
    public final static String AT_CMD_CD ="CD"; 
    public final static String AT_CMD_MM ="MM"; 
    public final static String AT_CMD_MN ="MN";
	public final static String AT_CMD_CY ="CY";
	public final static String AT_CMD_CE ="CE";
	public final static String AT_CMD_CF ="CF";
	public final static String AT_CMD_CG ="CG";
	public final static String AT_CMD_CH ="CH"; 
	public final static String AT_CMD_CM ="CM";
	public final static String AT_CMD_CO ="CO";
	public final static String AT_CMD_PW ="PW"; 
	public final static String AT_CMD_MZ ="MZ"; 
	public final static String AT_CMD_MF ="MF"; 
	public final static String AT_CMD_MG ="MG"; 
	public final static String AT_CMD_MH ="MH"; 
	public final static String AT_CMD_MP ="MP";
	public final static String AT_CMD_MQ ="MQ"; 
	public final static String AT_CMD_MK ="MK";
	
	public final static String AT_CMD_MA ="MA";
	public final static String AT_CMD_MB ="MB";
	public final static String AT_CMD_MD ="MD"; 
	public final static String AT_CMD_ME ="ME"; 
	public final static String AT_CMD_CK ="CK"; 
	public final static String AT_CMD_CL ="CL"; 
	
	public final static String AT_INFO_MM ="MM";
	public final static String AT_INFO_MG ="MG"; 
	public final static String AT_INFO_MY ="MY"; 
	public final static String AT_INFO_MD ="MD"; 
	public final static String AT_INFO_MC ="MC"; 
	public final static String AT_INFO_CM ="MC"; 
	public final static String AT_INFO_IA ="IA"; 
	public final static String AT_INFO_IB ="IB"; 
	public final static String AT_INFO_IC ="IC";
	public final static String AT_INFO_IG ="IG";
	public final static String AT_INFO_ID ="ID"; 
	public final static String AT_INFO_IF ="IF"; 
	public final static String AT_INFO_IR ="IR";
	public final static String AT_INFO_PB ="PB";
	public final static String AT_INFO_PC ="PC";
	
	public final static String AT_CMD_CZ ="CZ";
	public final static String AT_CMD_CV ="CV";

	public final static String AT_INFO_MA ="MA"; 
	public final static String AT_INFO_MB ="MB";
	
	public static interface AnywheeBtActionListener  {	   	 	 
	    public abstract boolean   GetBtState();
		public abstract boolean   SetBtState(boolean btState,BluetoothDevice dev);
		public abstract String    GetBtName();
		public abstract void      SetBtName(String btName);
		public abstract String    GetLocalBtName();
		public abstract void      SetLocalBtName(String btName);
		public abstract int 	  SetCmdBt(String strCmd,int delay);	
		public abstract int 	  SetCmdBtPara(String strCmd,String para,int delay);
	   	public abstract int   	  SyncCallPb(int target,int offset,int count);  
	    public abstract int       CallPhone(String number);									
		public abstract void 	  OpenCallView(String str);		
		public abstract boolean   GetBtStartState();

		public abstract void 	  SetBtPassThroughCmd(int keyCode, int keyState);
		public abstract void 	  hangupCall();
		public abstract void 	  terminateCall();
		public abstract void 	  acceptCall();
		public abstract void 	  StartIncomingActivity(String num);
		public abstract boolean	  getPbap();
		public abstract String    GetBtAddress();

		public abstract boolean   GetNetWorkService();
	
		public abstract boolean   SetNetWorkService(boolean netWork);

		public abstract boolean   ConnectA2dpSinkDevice(BluetoothDevice dev);
		public abstract boolean   DisConnectA2dpSinkDevice(BluetoothDevice dev);

		public abstract void   	  SetBtA2dpSinkState(boolean btState,BluetoothDevice dev);
		public abstract boolean   ConnectHfpclientDevice(BluetoothDevice dev);
		public abstract boolean   DisConnectHfpclientDevice(BluetoothDevice dev);
		public abstract void      setBtHfpclientState(int btState,BluetoothDevice dev);
		public abstract int       getBtHfpclientState();
		public abstract BluetoothDevice getBtHfpclientDevice();
		
		public abstract List<BtContact> queryPeoplesByName(String name, String s);

		public abstract void      setCallState(int state);		
		public abstract int       getCallState();
		public abstract void      sendDTMF(String number);

		public abstract void      setCtHandler(Handler handler);

		public abstract void      connectAudio();

		public abstract void      disConnectAudio();
   }
	
    public static void SetActionListener(AnywheeBtActionListener listener)	{
	    mListener = listener;
	    Log.i(TAG, (new StringBuilder()).append("SetActionListener, mListener = ").append(mListener).toString());
	}  

    public static String GetBtName()    {
		if(mListener == null) return "";		
		return mListener.GetBtName();
    }
	public static void SetBtName(String btName)    {
		if(mListener != null)	
			mListener.SetBtName(btName);
    }
    public static boolean GetBtState() {
    	if(mListener == null) return false;		
		return mListener.GetBtState();	    	
    }
	public  static String    GetBtAddress(){
		if(mListener == null) return "";		
		return mListener.GetBtAddress();

	}
	public static boolean SetBtState(boolean btState,BluetoothDevice dev) {
    	if(mListener == null) return false;		
		return mListener.SetBtState(btState,dev);	    	
    }
    public static int SetCmdBt(String strCmd,int delay) {
    	//*if(mListener == null) return -1;		
		//*return mListener.SetCmdBt(strCmd,delay);
		return 1;
    }
    public static int SetCmdBtPara(String strCmd,String para,int delay) {
    	if(mListener == null) return -1;		
		return mListener.SetCmdBtPara(strCmd,para,delay);	    	
    }    
    public static int SyncCallPb(int target,int offset,int count) {
    	if(mListener == null) return -1;		
		return mListener.SyncCallPb(target,offset,count);	    	
    }
    
    public static int CallPhone(String number)    {
		if(mListener == null) return -1;		
		return mListener.CallPhone(number);
    }
    
    public static void OpenCallView(String str) {
    	if(mListener == null) return;		
		mListener.OpenCallView(str);	
    }
    
    public static boolean GetBtStartState() {
    	if(mListener == null) return false;		
		return mListener.GetBtStartState();	
    }

	public static void 	  SetBtPassThroughCmd(int keyCode, int keyState){
		if(mListener == null) return;		
			mListener.SetBtPassThroughCmd(keyCode,keyState);
	}
	public static void 	  hangupCall(){
		if(mListener == null) return;		
			mListener.hangupCall();
	}
	public	static void terminateCall(){
		if(mListener == null) return;		
			mListener.terminateCall();
	}
	public	static void acceptCall(){
		if(mListener == null) return;		
			mListener.acceptCall();
	}
	public	static void StartIncomingActivity(String num){
		if(mListener == null) return;		
			mListener.StartIncomingActivity(num);
	}
	public static boolean	getPbap(){
		if(mListener == null) return false;		
		return mListener.getPbap();

	}

	
	public static String GetLocalBtName()    {
		if(mListener == null) return "";		
		return mListener.GetLocalBtName();
    }
	public static void SetLocalBtName(String btName)    {
		if(mListener != null)	
			mListener.SetLocalBtName(btName);
    }


	public static boolean GetNetWorkService() {
		if(mListener == null) return false;		
		return mListener.GetNetWorkService();
	}
	
	public static boolean SetNetWorkService(boolean netWork) {
		if(mListener == null) return false;		
		return mListener.SetNetWorkService(netWork);
	}
	public static boolean   ConnectA2dpSinkDevice(BluetoothDevice dev){
		if(mListener == null) return false;		
			return mListener.ConnectA2dpSinkDevice(dev);
	}
	public static boolean   DisConnectA2dpSinkDevice(BluetoothDevice dev){
		if(mListener == null) return false;		
			return mListener.DisConnectA2dpSinkDevice(dev);
	}
	public static void   SetBtA2dpSinkState(boolean btState,BluetoothDevice dev){
		if(mListener != null)
			mListener.SetBtA2dpSinkState(btState,dev);
	}
	public static boolean   ConnectHfpclientDevice(BluetoothDevice dev){
		if(mListener == null) return false;		
			return mListener.ConnectHfpclientDevice(dev);
	}
	public static boolean   DisConnectHfpclientDevice(BluetoothDevice dev){
		if(mListener == null) return false;		
			return mListener.DisConnectHfpclientDevice(dev);
	}
	public static void   setBtHfpclientState(int btState,BluetoothDevice dev){
		if(mListener != null)
			mListener.setBtHfpclientState(btState,dev);
	}
	public static int getBtHfpclientState() {
    	if(mListener == null) return 0;		
		return mListener.getBtHfpclientState();	    	
    }
	public  static BluetoothDevice getBtHfpclientDevice(){
		if(mListener == null) return null;		
		return mListener.getBtHfpclientDevice();	 
	}
	public static List<BtContact> queryPeoplesByName(String name, String s) {
        if(mListener == null) {
            Log.e("JK_BluetoothService", "mListener is null");
            return null;
        }
        Log.e("JK_BluetoothService", "mListener is not null");
        return mListener.queryPeoplesByName(name, s);
    }
	public  static void      setCallState(int state){
		if(mListener == null) return ;		
		mListener.setCallState(state);	
	}
	public  static int      getCallState(){
		if(mListener == null) 
			return BluetoothHeadsetClientCall.CALL_STATE_TERMINATED;		
		return mListener.getCallState();	   
	}
	public static void      sendDTMF(String number){
		if(mListener == null) return ;		
		mListener.sendDTMF(number);	
	}
	public static void      setCtHandler(Handler handler){
		if(mListener == null) return ;		
		mListener.setCtHandler(handler);	
	}
	
	public static void      connectAudio(){
		if(mListener == null) return ;		
		mListener.connectAudio();	
	}

	public static void      disConnectAudio(){
		if(mListener == null) return ;		
		mListener.disConnectAudio();
	}
}
